Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to wait till mongo container becomes available #80

Closed
wants to merge 6 commits into from

Conversation

smparekh
Copy link

Replicates the wait functionality available in the redis module, during the use of current version ran into an issue with mongo:4 where it was taking a little longer to start the container before pytest ran the unit tests. Currently, I have had to add code to wait for log statements as such:

@pytest.fixture(scope="session")
def test_client():
    # init mongo
    mongo_container = MongoDbContainer("mongo:4").start()
    wait_for_logs(mongo_container, 'waiting for connections on port 27017')
    ...

but I believe the container should wait on start for it to finish spawning.

@smparekh
Copy link
Author

Tests are failing because of:

E   docker.errors.ImageNotFound: 404 Client Error: Not Found ("No such image: hello-world:latest")

for all python versions, it might have been a connection issue to Docker Hub, rerequesting the build run

@smparekh
Copy link
Author

smparekh commented Apr 3, 2020

@tillahoffmann , any chance you can rerun the travis build? I can't seem to kick it off, hopefully the image pull issue is fixed

@tillahoffmann
Copy link
Collaborator

@smparekh, I don't have the privileges to restart a build, unfortunately. Force-pushing may retrigger the build, however.

@smparekh
Copy link
Author

smparekh commented Apr 3, 2020

Not sure why build is failing on travis, I ran the tests locally for python 3.7 as a sanity check and the test in question passes:

tests/test_core.py::test_wait_for_hello
Pulling image hello-world
⠋
Container started:  2088cf603a
PASSED

in fact all tests pass:

---------- coverage: platform darwin, python 3.7.7-final-0 -----------
Name                                   Stmts   Miss Branch BrPart  Cover
------------------------------------------------------------------------
testcontainers/core/container.py          76      5     10      4    90%
testcontainers/core/docker_client.py      12      2      0      0    83%
testcontainers/core/utils.py              21     10      6      0    41%
testcontainers/core/waiting_utils.py      33      1      8      2    93%
testcontainers/elasticsearch.py           23      1      2      1    92%
testcontainers/general.py                  7      7      2      0     0%
testcontainers/google/pubsub.py           22      0      2      1    96%
testcontainers/mongodb.py                 29      5      0      0    83%
testcontainers/mysql.py                   31      5     12      6    74%
testcontainers/oracle.py                   9      4      0      0    56%
testcontainers/redis.py                   18      1      2      1    90%
testcontainers/selenium.py                27      2      2      1    90%
------------------------------------------------------------------------
TOTAL                                    393     43     50     16    85%

9 files skipped due to complete coverage.
Coverage HTML written to dir skip-covered


=================================================================== 20 passed, 1 skipped in 492.10s (0:08:12) ====================================================================

@smparekh
Copy link
Author

@tillahoffmann, was finally able to build and test via Travis, if you could take a look that would be great.

@alexanderankin
Copy link
Member

thank you @smparekh for your contribution - we are favoring log based waiting now, so im closing this in favor of #461

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants